import { ParsedArgs } from 'minimist';
import { saferRemove } from './utils';
import { join } from 'path';
import { CmdMap } from './types';
import { initWebBundle, buildWebBundle } from './web-bundle';
import { getDevConfig } from './conf';


export const cmds: CmdMap = {
	clean, build, watch
}

// --------- /Public Types --------- //

async function clean() {
	const configs = await getDevConfig();
	const cleanPaths = configs.cleanPaths;
	if (cleanPaths && cleanPaths.length > 0) {
		for (const cleanPath of cleanPaths) {
			saferRemove(cleanPath);
		}
	}
}

async function build(argv: ParsedArgs) {
	const configs = await getDevConfig();
	await initWebBundle(configs);
	await buildWebBundle(configs);
}

async function watch(argv: ParsedArgs) {
	const configs = await getDevConfig();
	await initWebBundle(configs);
	await buildWebBundle(configs, { watch: true });
}